package com.dream.cgomall.service.impl;

import com.dream.cgomall.service.ServiceResult;
import com.dream.cgomall.service.VerificationTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class verificationTokenServiceImpl implements VerificationTokenService {
    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public ServiceResult verificationToken(Integer id,String token) {
        try{
            Integer Realid= (Integer) redisTemplate.opsForValue().get(token);
            if(id!=null && (Realid==id || Realid.equals(id))){
                return ServiceResult.success();
            }
            return ServiceResult.notFound();
        }catch (RuntimeException runtimeException){
            return ServiceResult.notFound();
        }
    }
}
